home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / bookshelfChar.lua < prev    next >
Text File  |  2004-01-29  |  9KB  |  348 lines

  1. -- bookshelf character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.     end )
  6.     
  7.     onExit(function(msg)
  8. --        local bookshelf = retrieveStateObject("bookshelf");
  9. --        if (bookshelf) then
  10. --            getParent().unlockActionPoints(bookshelf);
  11. --            removeStateObject("bookshelf");
  12. --        end;
  13.         unlockAll("bookshelf");
  14.         unlockAll("book");
  15.     end )
  16.     
  17.     state("takeBoardgame")
  18.     
  19.         onEnter(function(msg)
  20.             local bookshelf = retrieveStateObject("bookshelf");
  21.             startAnimation("takeBoardgame");
  22.                         
  23.             if (bookshelf) then
  24.                 -- bookshelf does exist
  25.                 if (getParent().isOneActionPointLocked(bookshelf)) then
  26.                     -- action point is locked
  27.                     getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  28.                     sendMsg("emoThink", getParent().walkSO);
  29.                     exitStateMachine();
  30.                 else
  31.                     getParent().lockActionPoints(bookshelf);
  32.                 end
  33.             else
  34.                 -- bookshelf does not exist anymore
  35.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  36.                 sendMsg("emoThink", getParent().walkSO);
  37.                 exitStateMachine();
  38.             end
  39.             
  40.             freeHands(getParent());            
  41.             sendDelayedMsgThis("grabBoardgame", 1000);
  42.         end )
  43.     
  44.  
  45.         onMsg("grabBoardgame", function(msg)
  46.             print("create game");
  47.             local boardgame = getParent().loadGameObject("StandardGO","boardgameBox");
  48.             if (not boardgame) then
  49.                 print("create boardgame failed");
  50.             end
  51.             
  52.             storeStateObject("boardgame", boardgame);
  53.             getParent().attachLeftObjectHolder(boardgame);            
  54.             
  55.             local hso = getParent().handSO;
  56.             if (not hso) then
  57.                 print("no hands found");
  58.             else
  59.                 hso.setPose("leftHandHold");
  60.             end
  61.             
  62.         end)
  63.  
  64.  
  65.         onMsg("end", function(msg)
  66.             if testCancel() then
  67.                 freeHands(getParent());
  68.                 exitAndGoAway();
  69.             else            
  70.                 --setState("lookForChair");
  71.                 
  72.                 local boardgame = getParent().getLeftHeldObject();
  73.                 local wsoContext = StateMachineContext();
  74.                 wsoContext.storeStateObject("boardgame", boardgame);
  75.                 wsoContext.storeStateObject("tableObject", boardgame);
  76.                 wsoContext.storeData("chairCommand", "playByTableChar.sitDownWithGame");
  77.                 wsoContext.storeData("checkPartnerChair", true);
  78.                 queueStateMachine("tableChairChar.findChair", this, wsoContext);
  79.                 exitStateMachine();
  80.                                 
  81.             end
  82.         end )    
  83.         
  84.         onExit(function(msg)
  85.             -- getParent().detachObjectAnimator();
  86.         end)
  87.         
  88.         
  89.         
  90.         
  91.         
  92. --    -- look for free chair
  93. --    state("lookForChair")
  94. --        print("lookForChair");
  95. --    
  96. --        onEnter(function(msg)                
  97. --                
  98. --            local tablet = retrieveStateObject("tablet");
  99. --                                                
  100. --            getParent().handSO.setPose("leftHandHold");
  101. --            getParent().attachLeftObjectHolder(tablet);                            
  102. --            
  103. --            local wsoContext = StateMachineContext();
  104. --            wsoContext.storeStateObject("boardgame", boardgame);
  105. --            wsoContext.storeStateObject("tableObject", boardgame);
  106. --            wsoContext.storeData("chairCommand", "playByTableChar.sitDownWithGame");
  107. --            queueStateMachine("tableChairChar.findChair", this, wsoContext);
  108. --            exitStateMachine();
  109. --        end)
  110. --        
  111. --        
  112.         
  113.         
  114.         
  115. --        
  116. --    -- look for free chair
  117. --    state("lookForChair")
  118. --        print("lookForChair");
  119. --    
  120. --        onEnter(function(msg)
  121. --                -- find a chair to eat
  122. --                local boardgame = retrieveStateObject("boardgame");
  123. --
  124. --                local table, tableActionPointName, chair = getNextFreeChairByTable(getParent());
  125. --                if (chair) then
  126. --                    
  127. --                    -- go to chair
  128. --                    local actionPoint = getParent().getClosestFreeActionPoint(getParent(), chair, {"sit1", "sit2"});
  129. --                    if (actionPoint) then
  130. --                    
  131. --                        print("free chair found , ap:" .. actionPoint.getName());
  132. --                
  133. --                        
  134. --                        if (walkToActionPoint(actionPoint)) then
  135. --                        
  136. --                                                        
  137. --                            exitStateMachine();
  138. --                            storeStateObject("chair", chair);
  139. --                            storeStateObject("table", table);
  140. --                            storeStateObject("boardgame", boardgame);
  141. --                            storeStateObject("tableObject", boardgame);
  142. --                            storeData("tableActionPointName", tableActionPointName);
  143. --                            storeData("chairActionPointName", actionPoint.getName());
  144. --                        
  145. --                        
  146. --                            queueStateMachine("playByTableChar.sitDownWithGame", this);
  147. --                            
  148. --                            local hso = getParent().handSO;
  149. --                            hso.stopPose();
  150. --                                                        
  151. --                            local mirror = (actionPoint.getName() == "sit2");
  152. --                            print("actionPoint.getName(): ", actionPoint.getName()); 
  153. --                            print("mirror: ", mirror);
  154. --                            hso.setPose("leftHandHold", mirror);
  155. --                            
  156. --                            
  157. --                            if (mirror) then
  158. --                                print("switch hands");
  159. --                                -- switch hands
  160. --                                getParent().detachLeftObjectHolder();
  161. --                                getParent().attachRightObjectHolder(boardgame);                            
  162. --                            --else
  163. --                            --    getParent().attachLeftObjectHolder(boardgame);                            
  164. --                            end
  165. --                            
  166. --                        else
  167. --                            -- no path to chair was found
  168. --                            print("no path to action point");
  169. --                            sendMsgThis("noPlaceToPlay");
  170. --                        end
  171. --                                                
  172. --                    else
  173. --                        print("no free action point");
  174. --                        sendMsgThis("noPlaceToPlay");
  175. --                    end
  176. --                    
  177. --                    --exitStateMachine();                
  178. --                else
  179. --                    print("no free chair");
  180. --                    sendMsgThis("noPlaceToPlay");
  181. --                end
  182. --                
  183. --                
  184. --                
  185. --                
  186. --        
  187. --                
  188. --                            
  189. --                                                        
  190. --        
  191. --        end)
  192. --        
  193. --    onMsg("noPlaceToPlay", function(msg)
  194. --            print("no place to play");
  195. --            -- detach boardgame if attached to left hand
  196. --            getParent().detachLeftObjectHolder();
  197. --            getParent().detachRightObjectHolder();
  198. --            local boardgame = retrieveStateObject("boardgame");
  199. --            if (boardgame) then
  200. --                boardgame.deleteGameObject();
  201. --            end
  202. --            local hso = getParent().handSO;
  203. --            hso.stopPose();
  204. --            
  205. --            getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);            
  206. --            exitStateMachine();
  207. --            sendMsg("emoThink", getParent().walkSO);
  208. --        end)
  209.         
  210.         
  211.  
  212.  
  213.  
  214.  
  215.     state("takeBook")
  216.     
  217.         onEnter(function(msg)
  218.         
  219.             local bookshelf = retrieveStateObject("bookshelf");
  220.             if (bookshelf) then
  221.                 -- bookshelf does exist
  222.                 if (getParent().isOneActionPointLocked(bookshelf)) then
  223.                     -- action point is locked
  224.                     getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  225.                     sendMsg("emoThink", getParent().walkSO);
  226.                     exitStateMachine();
  227.                 else
  228.                     getParent().lockActionPoints(bookshelf);
  229.                     startAnimation("takeBook");
  230.                     freeHands(getParent());            
  231.                     sendDelayedMsgThis("grabBook", 1000);
  232.                 end
  233.             else
  234.                 -- bookshelf does not exist anymore
  235.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  236.                 sendMsg("emoThink", getParent().walkSO);
  237.                 exitStateMachine();
  238.             end
  239.             
  240.         end )
  241.     
  242.  
  243.         onMsg("grabBook", function(msg)
  244.             print("create book");
  245.             local book = getParent().loadGameObject("StandardGO","bookClosed");
  246.             if (not book) then
  247.                 print("create bookClosed failed");
  248.             end
  249.             
  250.             storeStateObject("book", book);
  251.             getParent().attachLeftObjectHolder(book);            
  252.             
  253.             
  254.         end)
  255.  
  256.  
  257.         onMsg("end", function(msg)
  258.             if testCancel() then
  259.                 -- detach book if attached to left hand
  260.                 local book = getParent().getLeftHeldObject();
  261.                 if (book) then
  262.                     getParent().detachLeftObjectHolder();
  263.                     book.deleteGameObject();
  264.                 end
  265. --                local hso = getParent().handSO;
  266. --                hso.stopPose();
  267.                 exitStateMachine();
  268.             else            
  269.                 local hso = getParent().handSO;
  270.                 if (not hso) then
  271.                     print("no hands found");
  272.                 else
  273.                     hso.setPose("leftHandHoldLow");
  274.                 end
  275.                 setState("lookForSeat");                
  276.             end
  277.         end )    
  278.         
  279.         onExit(function(msg)
  280.             -- getParent().detachObjectAnimator();
  281.         end)
  282.  
  283.  
  284.  
  285.     state("lookForSeat")
  286.         print("lookForSeat");
  287.     
  288.         onEnter(function(msg)
  289.             -- find a sofa to eat
  290.             local seat, actionPoint = getNextReadSit(getParent());
  291.             if (not seat) then
  292.                 sendMsgThis("noPlaceToRead");
  293.                 return            
  294.             end
  295.             
  296.             local wso = getParent().walkSO;
  297.             if (wso.walkToActionPoint(actionPoint)) then
  298.             
  299.                 -- create state machine contexts
  300.                 local wsoContext = StateMachineContext();
  301.                 --wsoContext.storeStateObject("seat", seat);
  302.                 wsoContext.storeStateObject("book", retrieveStateObject("book"));
  303.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  304.                 wsoContext.storeData("sitState", "readBook");
  305.                 wsoContext.storeData("bookType", retrieveData("bookType", "Novel"));
  306.                 
  307.                 wso.queueStateMachine("sofaChar.sitDown", seat, wsoContext);                
  308.                 exitStateMachine();
  309.             else
  310.                 print("no path found");
  311.                 sendMsgThis("noPlaceToRead");
  312.             end
  313.             
  314.             
  315.             
  316.             
  317.         end)
  318.  
  319.  
  320.     onMsg("noPlaceToRead", function(msg)
  321.             print("no place to read");
  322.             -- detach book if attached to left hand
  323.             local character = getParent();
  324. --            character.detachLeftObjectHolder();
  325. --            character.detachRightObjectHolder();
  326. --            local book = retrieveStateObject("book");
  327. --            if (book) then
  328. --                book.deleteGameObject();
  329. --            end
  330. --            character.handSO.stopPose();
  331.  
  332.             freeHands(getParent());
  333.             
  334.             instantAbort(character, EMOTICON_NOPATH, "emoThink");
  335.             exitStateMachine();
  336.             
  337.             
  338. --            getParent().setEmoticon(EMOTICON_NOSOFA, EMOTICON_DELAY);            
  339. --            exitStateMachine();
  340. --            sendMsg("emoThink", getParent().walkSO);
  341.         end)
  342.  
  343.  
  344.  
  345.     
  346.         
  347. endStateMachine()
  348.